#include <GL/glut.h>
#include "turtle.h"


#define SIZE 500  /* the size, in pixels, of the square window to open */

void display (void);
void init (void);

int main (int argc, char **argv){
   glutInit (&argc, argv);
   glutInitWindowSize (SIZE, SIZE);
   glutInitWindowPosition (50, 100);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
   glutCreateWindow ("Turtle API example");
   glutDisplayFunc (display);
   init ();
   glutMainLoop ();
   return 0;
}

void display (void){
	glClear (GL_COLOR_BUFFER_BIT);

	//Drawing a happy face using turtle graphics
	init(SIZE/2.0, SIZE/2.0, 90);

	pen(false);

	color(0,0,1);
	forward(60);
	right(90);
	forward(30);
	left(90);
	pen(true);
	forward(30);
	pen(false);
	left(90);
	forward(60);
	left(90);
	pen(true);
	forward(30);	

	color(0,1,0);
	init(SIZE/2.0, (SIZE/2.0)-50, 0);
   
	for(int i=0; i<145; i++){
		left(2.5);
		forward(5);
	}

	pen(false);

	left(90);
	forward(30);
	right(90);
	for(int i=0; i<25; i++){
		right(2.5);
		forward(-3);
	}

    pen(true);

	for(int i=0; i<50; i++){
		left(2.5);
		forward(3);
	}

	glutSwapBuffers ();
}

void init (){
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   gluOrtho2D (0, SIZE-1, 0, SIZE-1);
}

